﻿using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;

namespace EssenceFeed.Core.Helpers
{
    public static class CheckBoxListHelper
    {
        /*
        /// <summary>
        /// CheckBoxList
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="name"></param>
        /// <param name="items"></param>
        /// <returns></returns>
        public static string CheckBoxList(this HtmlHelper helper, string name, IDictionary<string, string> items)
        {
            return CheckBoxList(helper, name, items, null, null);
        }

        /// <summary>
        /// CheckBoxList
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="name"></param>
        /// <param name="items"></param>
        /// <param name="checkboxHtmlAttributes"></param>
        /// <returns></returns>
        public static string CheckBoxList(this HtmlHelper helper, string name, IDictionary<string, string> items,
                                          IDictionary<string, object> checkboxHtmlAttributes)
        {
            return CheckBoxList(helper, name, items, null, checkboxHtmlAttributes);
        }

        /// <summary>
        /// CheckBoxList
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="name"></param>
        /// <param name="items"></param>
        /// <param name="selectedValues"></param>
        /// <returns></returns>
        public static string CheckBoxList(this HtmlHelper helper, string name, IDictionary<string, string> items,IEnumerable<string> selectedValues)
        {
            return CheckBoxList(helper, name, items, selectedValues, null);
        }
        /*
        /// <summary>
        /// CheckBoxList
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="name"></param>
        /// <param name="items"></param>
        /// <param name="selectedValues"></param>
        /// <param name="checkboxHtmlAttributes"></param>
        /// <returns></returns>
        public static string CheckBoxList(this HtmlHelper helper, string name, IDictionary<string, string> items,IEnumerable<string> selectedValues,IDictionary<string, object> checkboxHtmlAttributes)
        {
            var selectListItems = from i in items select new SelectListItem
                                                                     {
                                                                         Text = i.Key,
                                                                         Value = i.Value,
                                                                         Selected =
                                                                             (selectedValues != null &&
                                                                              selectedValues.Contains(i.Value))
                                                                     };
            return CheckBoxList(helper, name, selectListItems, checkboxHtmlAttributes);
        }

        /// <summary>
        /// CheckBoxList
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="name"></param>
        /// <param name="items"></param>
        /// <returns></returns>
        public static string CheckBoxList(this HtmlHelper helper, string name, IEnumerable<SelectListItem> items)
        {
            return CheckBoxList(helper, name, items, null);
        }
        /*
        /// <summary>
        /// CheckBoxList
        /// </summary>
        /// <param name="helper"></param>
        /// <param name="name"></param>
        /// <param name="items"></param>
        /// <param name="checkboxHtmlAttributes"></param>
        /// <returns></returns>
        public static string CheckBoxList(this HtmlHelper helper, string name, IEnumerable<SelectListItem> items,
                                          IDictionary<string, object> checkboxHtmlAttributes)
        {
            var output = new StringBuilder();
            foreach (SelectListItem item in items)
            {
                output.Append("<div class=\"fields\"><label>");
                var checkboxList = new TagBuilder("input");
                checkboxList.MergeAttribute("type", "checkbox");
                checkboxList.MergeAttribute("name", name);
                checkboxList.MergeAttribute("value", item.Value);
                // Check to see if it's checked
                if (item.Selected)
                    checkboxList.MergeAttribute("checked", "checked");
                // Add any attributes
                if (checkboxHtmlAttributes != null)

                    checkboxList.MergeAttributes(checkboxHtmlAttributes);
                checkboxList.SetInnerText(item.Text);
                output.Append(checkboxList.ToString(TagRenderMode.SelfClosing));
                output.Append("&nbsp; " + item.Text + "</label></div>");
            }
            return output.ToString();
        }
         * */
    }
    
}